// SISTEMA.: INFOSEG/IDENTIFICACAO CRIMINAL
// PROGRAMA: INFSEGPA
// ANALISTA: SOLON MIRANDA
// DATA: 19/06/2001
// ATUALIZACAO.:
// OBJETIVO:- ACERTO DE REGISTROS REGEITADOS NA ATUALIZACAO DO
// ARQUIVO DO INDICE NACIONAL DO INFOSEG
package br.com.vti.sisp_sicrim.antigo.controller.programa;

import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.apache.commons.lang3.StringUtils;

import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.model.Infsegl9;
import br.com.vti.sisp_sicrim.antigo.model.SicCadastro;
import br.com.vti.sisp_sicrim.antigo.util.ExceptionProgram;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe : Infsegpa OBJETIVO:- ACERTO DE REGISTROS REGEITADOS NA ATUALIZACAO DO ARQUIVO DO INDICE NACIONAL DO INFOSEG *
 * 
 * @author Incode - Data: mai/2014
 * 
 */
@Resource
@Path("/antigo/infsegpa")
public class Infsegpa {
	// Views utilizadas
	SicCadastro criminalView = new SicCadastro();
	// Telas/relatorios utilizados
	// Includes utilizados
	Infsegl9 infsegl9 = new Infsegl9();
	// Areas globais / session
	// Funcoes/subrotinas
	FuncoesGerais funcoes = new FuncoesGerais();
	FileWriter arquivo1;
	
	Result result;
	Sessao sessao;
	Boolean primeiraVez = false;
	Infsegpa infsegpaAnterior;
	String faseproc = "0";
	private String nome = "";
	private int err = 0;
	private int pos = 0;
	private int horax = 0;
	private int horat = 0;
	private int contTr10 = 0;
	private int contTr11 = 0;
	private int contTr12 = 0;
	private int contGeral = 0;
	private int cnome = 0;
	private int cmae = 0;
	private int cpai = 0;
	private String regHeader = "";
	private String regTr10 = "";
	private String regTr11 = "";
	private String regTr12 = "";
	private String regFooter = "";

	public Infsegpa(Result result, Sessao sessao) {
		this.result = result;
		this.sessao = sessao;
	}

	@Post
	public void executar() {
		try {
			main();
		} catch (Exception e) {
			throw new ExceptionProgram(e, sessao, this.getClass().getSimpleName());
		}
	}

	private void main() throws Exception {
		arquivo1 = new FileWriter("arquivo1");
		// Par�grafo: l1()
		while (criminalView.pesquisaRegEstadualGeral((long) 31742)) {
			// 235
			nome = criminalView.getNomeCompleto();

			funcoes.validnom(nome);
			if (funcoes.err != 0) {
				cnome = 1;
				UtilBean.mensagemTexto("# ERRO NOME:", criminalView.getTipoReg(), criminalView.getRegEstadualGeral(), UtilBean.subStr(nome, 0, 30));
			}
			nome = criminalView.getNomePai();

			funcoes.validnom(nome);
			if (funcoes.err != 0) {
				cpai = 1;
				UtilBean.mensagemTexto("# ERRO NOME PAI:", criminalView.getTipoReg(), criminalView.getRegEstadualGeral(), UtilBean.subStr(nome, 0, 30));
			}
			nome = criminalView.getNomeMae();

			funcoes.validnom(nome);
			if (funcoes.err != 0) {
				cmae = 1;
				UtilBean.mensagemTexto("# ERRO NOME MAE:", criminalView.getTipoReg(), criminalView.getRegEstadualGeral(), UtilBean.subStr(nome, 0, 30));
			}
			if (cnome == 0) {
				switch (criminalView.getTipoReg()) {
				// && CPAI = 0 && CMAE = 0
				case "AL": {
					contTr11 += 1;
					break;
				}
				case "EX": {
					contTr12 += 1;
					break;
				}
				case "IN": {
					contTr10 += 1;
					break;
				}
				default: {
					continue;
				}
				}
			}

		}
		infsegl9.headerTipoReg = 00;
		infsegl9.headerUfReg = "MA";
		infsegl9.headerVersaoForm = "02";
		infsegl9.headerNomeHost = "FUJITSU";
		infsegl9.headerTipoArq = "IND";
		infsegl9.headerDataEnvio = UtilBean.obtemDataCorrente();
		// ARQUIVO DE ATUALIZACAO

		horax = Integer.parseInt((new SimpleDateFormat("HHmmssS").format(Calendar.getInstance().getTime())));

		infsegl9.headerHoraEnvio = horax;
		infsegl9.headerQtTr10 = contTr10;
		infsegl9.headerQtTr11 = contTr11;
		infsegl9.headerQtTr12 = contTr12;
		infsegl9.headerQtTr13 = 0;
		infsegl9.headerQtTr14 = 0;
		infsegl9.headerFiller1 = StringUtils.repeat(" ", 138);
		infsegl9.headerFiller2 = StringUtils.repeat(" ", 138);
		contGeral = contTr10 + contTr11 + contTr12;
		UtilBean.mensagemTexto(contGeral, contTr10, contTr11, contTr12);
		regHeader = UtilBean.moveSubstring(regHeader, 0, 2, "N", infsegl9.headerTipoReg);
		regHeader = UtilBean.moveSubstring(regHeader, 2, 2, "A", infsegl9.headerUfReg);
		regHeader = UtilBean.moveSubstring(regHeader, 4, 2, "A", infsegl9.headerVersaoForm);
		regHeader = UtilBean.moveSubstring(regHeader, 6, 10, "A", infsegl9.headerNomeHost);
		regHeader = UtilBean.moveSubstring(regHeader, 16, 3, "A", infsegl9.headerTipoArq);
		regHeader = UtilBean.moveSubstring(regHeader, 19, 8, "N", infsegl9.headerDataEnvio);
		regHeader = UtilBean.moveSubstring(regHeader, 27, 6, "N", infsegl9.headerHoraEnvio);
		regHeader = UtilBean.moveSubstring(regHeader, 33, 47, "A", infsegl9.headerReservado);
		regHeader = UtilBean.moveSubstring(regHeader, 80, 6, "N", infsegl9.headerQtTr10);
		regHeader = UtilBean.moveSubstring(regHeader, 86, 6, "N", infsegl9.headerQtTr11);
		regHeader = UtilBean.moveSubstring(regHeader, 92, 6, "N", infsegl9.headerQtTr12);
		regHeader = UtilBean.moveSubstring(regHeader, 98, 6, "N", infsegl9.headerQtTr13);
		regHeader = UtilBean.moveSubstring(regHeader, 104, 6, "N", infsegl9.headerQtTr14);
		regHeader = UtilBean.moveSubstring(regHeader, 110, 138, "A", infsegl9.headerFiller1);
		regHeader = UtilBean.moveSubstring(regHeader, 248, 138, "A", infsegl9.headerFiller2);
		arquivo1.write(regHeader); // / writeworkfile__
									// (;_CMDARGNFILEW;_CMDARGBUF;)
		//dao.rollback();
		// Par�grafo: l2()
		while (criminalView.pesquisaRegEstadualGeral((long) 31742)) {
			// 295
			nome = criminalView.getNomeCompleto();

			funcoes.validnom(nome);
			if (err == 0) {
				switch (criminalView.getTipoReg()) {
				case "AL": {
					regTr11();
					break;
				}
				case "EX": {
					regTr12();
					break;
				}
				case "IN": {
					regTr10();
					break;
				}
				default: {
					continue;
				}
				}
			}
		}

		infsegl9.footerTipoReg = 99;
		infsegl9.footerFiller1 = StringUtils.repeat(" ", 192);
		infsegl9.footerFiller2 = StringUtils.repeat(" ", 192);
		regFooter = UtilBean.moveSubstring(regFooter, 0, 2, "N", infsegl9.footerTipoReg);
		regFooter = UtilBean.moveSubstring(regFooter, 2, 192, "A", infsegl9.footerFiller1);
		regFooter = UtilBean.moveSubstring(regFooter, 194, 192, "A", infsegl9.footerFiller2);
		arquivo1.write(regFooter); // / writeworkfile__
									// (;_CMDARGNFILEW;_CMDARGBUF;)
		arquivo1.close();
		//dao.rollback();
		UtilBean.mensagemTexto("*** OK. FIM DA GERACAO DO ARQUIVO CRIMINAL ***");
	}

	private void regTr10() throws Exception {
		infsegl9.tr10TipoReg = 10;
		infsegl9.tr10DataAtualizaUf = criminalView.getDataDocAtu();

		horat = criminalView.getHoraAtu();
		infsegl9.tr10HoraAtualizaUf = horat;
		infsegl9.tr10VersaoFormato = "02";
		infsegl9.tr10UfRegCriminal = "MA";
		infsegl9.tr10NomeHostUf = "FUJITSU";
		infsegl9.tr10ChavePrimariaRgIgUf = String.valueOf(criminalView.getRegEstadualGeral());
		infsegl9.tr10Reservado = StringUtils.repeat(" ", 30);
		infsegl9.tr10NomeCompleto = criminalView.getNomeCompleto();
		nome = criminalView.getNomePai();

		funcoes.validnom(nome);
		if (funcoes.err != 0) {
			infsegl9.tr10NomePai = " ";
		} else {
			infsegl9.tr10NomePai = criminalView.getNomePai();
		}
		nome = criminalView.getNomeMae();

		funcoes.validnom(nome);
		if (funcoes.err != 0) {
			infsegl9.tr10NomeMae = " ";
		} else {
			infsegl9.tr10NomeMae = criminalView.getNomeMae();
		}
		infsegl9.tr10DataNasc = criminalView.getDataNasc();
		if (criminalView.getSexo() != 0) {
			if (criminalView.getSexo() == 1) {
				infsegl9.tr10Sexo = "M";
			} else {
				infsegl9.tr10Sexo = "F";
			}
		} else {
			infsegl9.tr10Sexo = " ";
		}
		infsegl9.tr10Cutis = criminalView.getCodigoCutis();
		infsegl9.tr10Naturalidade = criminalView.getNaturalidade();
		infsegl9.tr10UfNaturalidade = criminalView.getUfNaturalidade();
		infsegl9.tr10Nacionalidade = criminalView.getNacionalidade();
		infsegl9.tr10NacionalidadeEstrang = 0000;
		infsegl9.tr10TipoProprietarioArma = 00;
		infsegl9.tr10RegistroGeral = String.valueOf(criminalView.getRegEstadualGeral());
		infsegl9.tr10UfRegEstadualGeral = "MA";
		if (criminalView.getDataDocAtu() == 0) {

			infsegl9.tr10DataUltimaMovimentUf = String.valueOf(UtilBean.obtemDataCorrente());
		} else {

			infsegl9.tr10DataUltimaMovimentUf = String.valueOf(criminalView.getDataDocAtu());
		}
		infsegl9.tr10PossuiInquerito = criminalView.getInqueritoPolicial();
		infsegl9.tr10PossuiArma = criminalView.getPossuiArma();
		// TR10-POSSUI-INQUERITO := 'S'
		infsegl9.tr10PossuiProcesso = criminalView.getPossuiProcesso();
		// TR10-POSSUI-ARMA := 'N'
		if (criminalView.getObservacao(1).trim().equals("")) {
			infsegl9.tr10PossuiProcesso = "N";
		} else {
			infsegl9.tr10PossuiProcesso = "S";
		}
		infsegl9.tr10Falecido = criminalView.getFalecido();
		infsegl9.tr10PossuiMandatoPAberto = criminalView.getPossuiMandatoAberto();
		// TR10-FALECIDO := 'N'
		infsegl9.tr10Foragido = " ";
		// TR10-POSSUI-MANDATO-P-ABERTO := 'N'
		infsegl9.tr10CumprindoPena = " ";
		infsegl9.tr10Narcotrafico = " ";
		infsegl9.tr10InformaPenitenciarias = " ";
		infsegl9.tr10Imagens = " ";
		infsegl9.tr10Flag06 = " ";
		infsegl9.tr10Flag07 = " ";
		infsegl9.tr10Flag08 = " ";
		infsegl9.tr10UfOrigem = " ";
		regTr10 = UtilBean.moveSubstring(regTr10, 0, 2, "N", infsegl9.tr10TipoReg);
		regTr10 = UtilBean.moveSubstring(regTr10, 2, 8, "N", infsegl9.tr10DataAtualizaUf);
		regTr10 = UtilBean.moveSubstring(regTr10, 10, 6, "N", infsegl9.tr10HoraAtualizaUf);
		regTr10 = UtilBean.moveSubstring(regTr10, 16, 2, "A", infsegl9.tr10VersaoFormato);
		regTr10 = UtilBean.moveSubstring(regTr10, 18, 2, "A", infsegl9.tr10UfRegCriminal);
		regTr10 = UtilBean.moveSubstring(regTr10, 20, 10, "A", infsegl9.tr10NomeHostUf);
		regTr10 = UtilBean.moveSubstring(regTr10, 30, 20, "A", infsegl9.tr10ChavePrimariaRgIgUf);
		regTr10 = UtilBean.moveSubstring(regTr10, 50, 30, "A", infsegl9.tr10Reservado);
		regTr10 = UtilBean.moveSubstring(regTr10, 80, 70, "A", infsegl9.tr10NomeCompleto);
		regTr10 = UtilBean.moveSubstring(regTr10, 150, 70, "A", infsegl9.tr10NomePai);
		regTr10 = UtilBean.moveSubstring(regTr10, 220, 70, "A", infsegl9.tr10NomeMae);
		regTr10 = UtilBean.moveSubstring(regTr10, 290, 8, "N", infsegl9.tr10DataNasc);
		regTr10 = UtilBean.moveSubstring(regTr10, 298, 1, "A", infsegl9.tr10Sexo);
		regTr10 = UtilBean.moveSubstring(regTr10, 299, 2, "N", infsegl9.tr10Cutis);
		regTr10 = UtilBean.moveSubstring(regTr10, 301, 35, "A", infsegl9.tr10Naturalidade);
		regTr10 = UtilBean.moveSubstring(regTr10, 336, 2, "A", infsegl9.tr10UfNaturalidade);
		regTr10 = UtilBean.moveSubstring(regTr10, 338, 2, "N", infsegl9.tr10Nacionalidade);
		regTr10 = UtilBean.moveSubstring(regTr10, 340, 4, "N", infsegl9.tr10NacionalidadeEstrang);
		regTr10 = UtilBean.moveSubstring(regTr10, 344, 2, "N", infsegl9.tr10TipoProprietarioArma);
		regTr10 = UtilBean.moveSubstring(regTr10, 346, 15, "A", infsegl9.tr10RegistroGeral);
		regTr10 = UtilBean.moveSubstring(regTr10, 361, 2, "A", infsegl9.tr10UfRegEstadualGeral);
		regTr10 = UtilBean.moveSubstring(regTr10, 363, 8, "A", infsegl9.tr10DataUltimaMovimentUf);
		regTr10 = UtilBean.moveSubstring(regTr10, 371, 1, "A", infsegl9.tr10PossuiInquerito);
		regTr10 = UtilBean.moveSubstring(regTr10, 372, 1, "A", infsegl9.tr10PossuiArma);
		regTr10 = UtilBean.moveSubstring(regTr10, 373, 1, "A", infsegl9.tr10PossuiProcesso);
		regTr10 = UtilBean.moveSubstring(regTr10, 374, 1, "A", infsegl9.tr10Falecido);
		regTr10 = UtilBean.moveSubstring(regTr10, 375, 1, "A", infsegl9.tr10PossuiMandatoPAberto);
		regTr10 = UtilBean.moveSubstring(regTr10, 376, 1, "A", infsegl9.tr10Foragido);
		regTr10 = UtilBean.moveSubstring(regTr10, 377, 1, "A", infsegl9.tr10CumprindoPena);
		regTr10 = UtilBean.moveSubstring(regTr10, 378, 1, "A", infsegl9.tr10Narcotrafico);
		regTr10 = UtilBean.moveSubstring(regTr10, 379, 1, "A", infsegl9.tr10InformaPenitenciarias);
		regTr10 = UtilBean.moveSubstring(regTr10, 380, 1, "A", infsegl9.tr10Imagens);
		regTr10 = UtilBean.moveSubstring(regTr10, 381, 1, "A", infsegl9.tr10Flag06);
		regTr10 = UtilBean.moveSubstring(regTr10, 382, 1, "A", infsegl9.tr10Flag07);
		regTr10 = UtilBean.moveSubstring(regTr10, 383, 1, "A", infsegl9.tr10Flag08);
		regTr10 = UtilBean.moveSubstring(regTr10, 384, 2, "A", infsegl9.tr10UfOrigem);
		arquivo1.write(regTr10); // / writeworkfile__
									// (;_CMDARGNFILEW;_CMDARGBUF;)
		//dao.rollback();
	}

	private void regTr11() throws Exception {
		infsegl9.tr11TipoReg = 11;
		infsegl9.tr11DataAtualizaUf = criminalView.getDataDocAtu();

		horat = criminalView.getHoraAtu();
		infsegl9.tr11HoraAtualizaUf = horat;

		infsegl9.tr11VersaoFormato = "02";
		infsegl9.tr11UfRegCriminal = "MA";
		infsegl9.tr11NomeHostUf = "FUJITSU";
		infsegl9.tr11ChavePrimariaRgIgUf = String.valueOf(criminalView.getRegEstadualGeral());
		infsegl9.tr11Reservado = StringUtils.repeat(" ", 30);
		infsegl9.tr11NomeCompleto = criminalView.getNomeCompleto();
		nome = criminalView.getNomePai();

		funcoes.validnom(nome);
		if (funcoes.err != 0) {
			infsegl9.tr11NomePai = " ";
		} else {
			infsegl9.tr11NomePai = criminalView.getNomePai();
		}
		nome = criminalView.getNomeMae();

		funcoes.validnom(nome);
		if (funcoes.err != 0) {
			infsegl9.tr11NomeMae = " ";
		} else {
			infsegl9.tr11NomeMae = criminalView.getNomeMae();
		}
		infsegl9.tr11DataNasc = criminalView.getDataNasc();
		if (criminalView.getSexo() != 0) {
			if (criminalView.getSexo() == 1) {
				infsegl9.tr11Sexo = "M";
			} else {
				infsegl9.tr11Sexo = "F";
			}
		} else {
			infsegl9.tr11Sexo = " ";
		}
		infsegl9.tr11Cutis = criminalView.getCodigoCutis();
		infsegl9.tr11Naturalidade = criminalView.getNaturalidade();
		infsegl9.tr11UfNaturalidade = criminalView.getUfNaturalidade();
		infsegl9.tr11Nacionalidade = criminalView.getNacionalidade();
		infsegl9.tr11NacionalidadeEstrang = 0000;
		infsegl9.tr11TipoProprietarioArma = 00;
		infsegl9.tr11RegistroGeral = String.valueOf(criminalView.getRegEstadualGeral());
		infsegl9.tr11UfRegEstadualGeral = "MA";
		if (criminalView.getDataDocAtu() == 0) {

			infsegl9.tr11DataUltimaMovimentUf = String.valueOf(UtilBean.obtemDataCorrente());
		} else {

			infsegl9.tr11DataUltimaMovimentUf = String.valueOf(criminalView.getDataDocAtu());
		}
		infsegl9.tr11PossuiInquerito = criminalView.getInqueritoPolicial();
		infsegl9.tr10PossuiArma = criminalView.getPossuiArma();
		// TR11-POSSUI-INQUERITO := 'S'
		infsegl9.tr11PossuiProcesso = criminalView.getPossuiProcesso();
		// TR11-POSSUI-ARMA := 'N'
		if (criminalView.getObservacao(1).trim().equals("")) {
			infsegl9.tr11PossuiProcesso = "N";
		} else {
			infsegl9.tr11PossuiProcesso = "S";
		}
		infsegl9.tr11Falecido = criminalView.getFalecido();
		infsegl9.tr10PossuiMandatoPAberto = criminalView.getPossuiMandatoAberto();
		// TR11-FALECIDO := 'N'
		infsegl9.tr11Foragido = " ";
		// TR11-POSSUI-MANDATO-P-ABERTO := 'N'
		infsegl9.tr11CumprindoPena = " ";
		infsegl9.tr11Narcotrafico = " ";
		infsegl9.tr11InformaPenitenciarias = " ";
		infsegl9.tr11Imagens = " ";
		infsegl9.tr11Flag06 = " ";
		infsegl9.tr11Flag07 = " ";
		infsegl9.tr11Flag08 = " ";
		infsegl9.tr11UfOrigem = " ";
		regTr11 = UtilBean.moveSubstring(regTr11, 0, 2, "N", infsegl9.tr11TipoReg);
		regTr11 = UtilBean.moveSubstring(regTr11, 2, 8, "N", infsegl9.tr11DataAtualizaUf);
		regTr11 = UtilBean.moveSubstring(regTr11, 10, 6, "N", infsegl9.tr11HoraAtualizaUf);
		regTr11 = UtilBean.moveSubstring(regTr11, 16, 2, "A", infsegl9.tr11VersaoFormato);
		regTr11 = UtilBean.moveSubstring(regTr11, 18, 2, "A", infsegl9.tr11UfRegCriminal);
		regTr11 = UtilBean.moveSubstring(regTr11, 20, 10, "A", infsegl9.tr11NomeHostUf);
		regTr11 = UtilBean.moveSubstring(regTr11, 30, 20, "A", infsegl9.tr11ChavePrimariaRgIgUf);
		regTr11 = UtilBean.moveSubstring(regTr11, 50, 30, "A", infsegl9.tr11Reservado);
		regTr11 = UtilBean.moveSubstring(regTr11, 80, 70, "A", infsegl9.tr11NomeCompleto);
		regTr11 = UtilBean.moveSubstring(regTr11, 150, 70, "A", infsegl9.tr11NomePai);
		regTr11 = UtilBean.moveSubstring(regTr11, 220, 70, "A", infsegl9.tr11NomeMae);
		regTr11 = UtilBean.moveSubstring(regTr11, 290, 8, "N", infsegl9.tr11DataNasc);
		regTr11 = UtilBean.moveSubstring(regTr11, 298, 1, "A", infsegl9.tr11Sexo);
		regTr11 = UtilBean.moveSubstring(regTr11, 299, 2, "N", infsegl9.tr11Cutis);
		regTr11 = UtilBean.moveSubstring(regTr11, 301, 35, "A", infsegl9.tr11Naturalidade);
		regTr11 = UtilBean.moveSubstring(regTr11, 336, 2, "A", infsegl9.tr11UfNaturalidade);
		regTr11 = UtilBean.moveSubstring(regTr11, 338, 2, "N", infsegl9.tr11Nacionalidade);
		regTr11 = UtilBean.moveSubstring(regTr11, 340, 4, "N", infsegl9.tr11NacionalidadeEstrang);
		regTr11 = UtilBean.moveSubstring(regTr11, 344, 2, "N", infsegl9.tr11TipoProprietarioArma);
		regTr11 = UtilBean.moveSubstring(regTr11, 346, 15, "A", infsegl9.tr11RegistroGeral);
		regTr11 = UtilBean.moveSubstring(regTr11, 361, 2, "A", infsegl9.tr11UfRegEstadualGeral);
		regTr11 = UtilBean.moveSubstring(regTr11, 363, 8, "A", infsegl9.tr11DataUltimaMovimentUf);
		regTr11 = UtilBean.moveSubstring(regTr11, 371, 1, "A", infsegl9.tr11PossuiInquerito);
		regTr11 = UtilBean.moveSubstring(regTr11, 372, 1, "A", infsegl9.tr11PossuiArma);
		regTr11 = UtilBean.moveSubstring(regTr11, 373, 1, "A", infsegl9.tr11PossuiProcesso);
		regTr11 = UtilBean.moveSubstring(regTr11, 374, 1, "A", infsegl9.tr11Falecido);
		regTr11 = UtilBean.moveSubstring(regTr11, 375, 1, "A", infsegl9.tr11PossuiMandatoPAberto);
		regTr11 = UtilBean.moveSubstring(regTr11, 376, 1, "A", infsegl9.tr11Foragido);
		regTr11 = UtilBean.moveSubstring(regTr11, 377, 1, "A", infsegl9.tr11CumprindoPena);
		regTr11 = UtilBean.moveSubstring(regTr11, 378, 1, "A", infsegl9.tr11Narcotrafico);
		regTr11 = UtilBean.moveSubstring(regTr11, 379, 1, "A", infsegl9.tr11InformaPenitenciarias);
		regTr11 = UtilBean.moveSubstring(regTr11, 380, 1, "A", infsegl9.tr11Imagens);
		regTr11 = UtilBean.moveSubstring(regTr11, 381, 1, "A", infsegl9.tr11Flag06);
		regTr11 = UtilBean.moveSubstring(regTr11, 382, 1, "A", infsegl9.tr11Flag07);
		regTr11 = UtilBean.moveSubstring(regTr11, 383, 1, "A", infsegl9.tr11Flag08);
		regTr11 = UtilBean.moveSubstring(regTr11, 384, 2, "A", infsegl9.tr11UfOrigem);
		arquivo1.write(regTr11); // / writeworkfile__
									// (;_CMDARGNFILEW;_CMDARGBUF;)
		//dao.rollback();
	}

	private void regTr12() throws IOException {
		infsegl9.tr12TipoReg = 12;
		infsegl9.tr12DataAtualizaUf = criminalView.getDataDocAtu();

		horat = criminalView.getHoraAtu();
		infsegl9.tr12HoraAtualizaUf = horat;
		infsegl9.tr12VersaoFormato = "02";
		infsegl9.tr12UfRegCriminal = "MA";
		infsegl9.tr12NomeHostUf = "FUJITSU";
		infsegl9.tr12ChavePrimariaRgIgUf = String.valueOf(criminalView.getRegEstadualGeral());
		infsegl9.tr12ChavePrimariaRgIgUf = String.valueOf(criminalView.getRegEstadualGeral());
		infsegl9.tr12Reservado = StringUtils.repeat(" ", 30);
		infsegl9.tr12Filler1 = StringUtils.repeat(" ", 153);
		infsegl9.tr12Filler2 = StringUtils.repeat(" ", 153);
		regTr12 = UtilBean.moveSubstring(regTr12, 0, 2, "N", infsegl9.tr12TipoReg);
		regTr12 = UtilBean.moveSubstring(regTr12, 2, 8, "N", infsegl9.tr12DataAtualizaUf);
		regTr12 = UtilBean.moveSubstring(regTr12, 10, 6, "N", infsegl9.tr12HoraAtualizaUf);
		regTr12 = UtilBean.moveSubstring(regTr12, 16, 2, "A", infsegl9.tr12VersaoFormato);
		regTr12 = UtilBean.moveSubstring(regTr12, 18, 2, "A", infsegl9.tr12UfRegCriminal);
		regTr12 = UtilBean.moveSubstring(regTr12, 20, 10, "A", infsegl9.tr12NomeHostUf);
		regTr12 = UtilBean.moveSubstring(regTr12, 30, 20, "A", infsegl9.tr12ChavePrimariaRgIgUf);
		regTr12 = UtilBean.moveSubstring(regTr12, 50, 30, "A", infsegl9.tr12Reservado);
		regTr12 = UtilBean.moveSubstring(regTr12, 80, 153, "A", infsegl9.tr12Filler1);
		regTr12 = UtilBean.moveSubstring(regTr12, 233, 153, "A", infsegl9.tr12Filler2);
		arquivo1.write(regTr12); // / writeworkfile__
									// (;_CMDARGNFILEW;_CMDARGBUF;)
		//dao.rollback();
	}

}
